<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue10</title>
    <script src="./vue.min.js"></script>
</head>
<body>
    <div id="app">
        <todo>
            <todo-title slot="todo-title" :title="title"></todo-title>
            <todo-list slot="todo-list" v-for="(item,index) in source" :item="item" :index="index" @remove="removeItems(index)">
            </todo-list>
        </todo>
    </div>
    
</body>
<script>
    Vue.component('todo',{
        template:'<div>\
            <slot name="todo-title"></slot>\
            <ul>\
                <slot name="todo-list"></slot>\
            </ul>\
        </div>'
    });
    Vue.component('todo-title',{
        props:['title'],
        template:'<h2>{{title}}</h2>'
    });
    Vue.component('todo-list',{
        props:['item','index'],
        template:'<li>{{index}}--{{item}}&nbsp;&nbsp;<button @click="removeItem(index)">删除</button></li>',
        methods: {
            removeItem:function (index){
                this.$emit('remove',index);//自定义事件分发，无法直接获取vue里面的方法，只能使用分发
            }
        }
    });
    var vue = new Vue({
        el:'#app',
        data:{
            title:"编程语言",
            source:["Java","vue","HTML"]
        },
        methods:{
            removeItems:function (index){//
                console.log("删除了"+this.source[index]);
                this.source.splice(index,1);
            }
        }
    })
</script>
</html>